package com.example.demo.study;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class Study14 {
    public static void main(String[] args) {
        HashMap <String, String> map = new HashMap<>();
        map.put("1", "a");
        map.put("2", "b");
        map.put("3", "c");
        map.put("4", "d");
        System.out.println(map.size());
        System.out.println(map.get("3"));
        System.out.println(map.containsKey("4"));
        System.out.println(map.containsValue("b"));
        System.out.println(map.keySet());
        System.out.println(map.values());
        for(String key :map.keySet()){
            System.out.println(key);
        }
        System.out.println("--------------------");
        for(String key :map.values()){
            System.out.println(key);
        }

        System.out.println("--------------------");
        // 迭代器
        Iterator iterator = map.keySet().iterator();
        while (iterator.hasNext()){
            String key = (String) iterator.next();
            System.out.println(key+":"+map.get(key));
        }
        System.out.println("--------------------");
        // 增强for
        for(String key :map.keySet()){
            System.out.println(key+":"+map.get(key));
        }
        System.out.println("--------------------");
        // 转换成list
        List<String> list = new ArrayList<>();
        for(String key :map.keySet()){
            list.add(key+":"+map.get(key));
        }
        System.out.println(list.size());

    }
}
